<?php
/**
 * 功能说明：
 * 参数说明：
 * 返回值：
 * 备注说明：
 * 作者：Administrator
 * 最后一次修改时间:2017/3/17 9:58
 */

namespace logic;


class Debug
{
	private $check_dev = false;

	public function run(){
		if( config('gobal.debugFlag') ){
			$ipStr = request()->ip();
			$ipArr = explode('.',$ipStr);
			if( $ipArr[0] == '192' or $ipArr[0] == '127' ) {
				$this->opera();
			}
			if( in_array($ipStr,config('gobal.debugIp')) ){
				$this->opera();
			}
			if( $this->ipWhiteList( $ipStr ) ){
				$this->opera();
			}
			if($ipArr[0] == '101' && $ipArr[1] == '226' && $ipArr[2] == '233'){
				$this->opera();
			}

			//非上线项目禁止外部访问
			!$this->check_dev &&  exit("error:$ipStr");

		}
	}

	private function opera(){
		$this->check_dev = true;
		error_reporting(E_ALL);
		ini_set('display_errors', '1');
		view()->assign('check_dev',$this->check_dev);
	}

	/*
	 * 微信服务器ip地址列表
	 */
	private function ipWhiteList( $ip ){
		$ipList = [
			"101.226.233.154",
			"101.226.233.152",
			"101.226.233.151",
			"101.226.62.77",
			"101.226.62.78",
			"101.226.62.79",
			"101.226.62.80",
			"101.226.62.81",
			"101.226.62.82",
			"101.226.62.83",
			"101.226.62.84",
			"101.226.62.85",
			"101.226.62.86",
			"101.226.103.59",
			"101.226.103.60",
			"101.226.103.61",
			"101.226.103.62",
			"101.226.103.63",
			"101.226.103.69",
			"101.226.103.70",
			"101.226.103.71",
			"101.226.103.72",
			"101.226.103.73",
			"140.207.54.73",
			"140.207.54.74",
			"140.207.54.75",
			"140.207.54.76",
			"140.207.54.77",
			"140.207.54.78",
			"140.207.54.79",
			"140.207.54.80",
			"182.254.11.203",
			"182.254.11.202",
			"182.254.11.201",
			"182.254.11.200",
			"182.254.11.199",
			"182.254.11.198",
			"59.37.97.100",
			"59.37.97.101",
			"59.37.97.102",
			"59.37.97.103",
			"59.37.97.104",
			"59.37.97.105",
			"59.37.97.106",
			"59.37.97.107",
			"59.37.97.108",
			"59.37.97.109",
			"59.37.97.110",
			"59.37.97.111",
			"59.37.97.112",
			"59.37.97.113",
			"59.37.97.114",
			"59.37.97.115",
			"59.37.97.116",
			"59.37.97.117",
			"59.37.97.118",
			"112.90.78.158",
			"112.90.78.159",
			"112.90.78.160",
			"112.90.78.161",
			"112.90.78.162",
			"112.90.78.163",
			"112.90.78.164",
			"112.90.78.165",
			"112.90.78.166",
			"112.90.78.167",
			"140.207.54.19",
			"140.207.54.76",
			"140.207.54.77",
			"140.207.54.78",
			"140.207.54.79",
			"140.207.54.80",
			"180.163.15.149",
			"180.163.15.151",
			"180.163.15.152",
			"180.163.15.153",
			"180.163.15.154",
			"180.163.15.155",
			"180.163.15.156",
			"180.163.15.157",
			"180.163.15.158",
			"180.163.15.159",
			"180.163.15.160",
			"180.163.15.161",
			"180.163.15.162",
			"180.163.15.163",
			"180.163.15.164",
			"180.163.15.165",
			"180.163.15.166",
			"180.163.15.167",
			"180.163.15.168",
			"180.163.15.169",
			"180.163.15.170",
			"101.226.103.0/25",
			"101.226.233.128/25",
			"58.247.206.128/25",
			"182.254.86.128/25",
			"103.7.30.21",
			"103.7.30.64/26",
			"58.251.80.32/27",
			"183.3.234.32/27",
			"121.51.130.64/27"
		];
		foreach ($ipList as $d){
			if( $ip == $d ){ return true; }
		}
		return false;
	}

}